package com.ctgu.redislock02.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ ClassName RabbitMQConfig
 * @ Author Alex2
 * @ Date 2025/9/11 8:43
 **/
@Configuration
public class RabbitMQConfig {

    public static final String QUEUE_PRODUCT_ORDER = "product_order_queue";
    public static final String EXCHANGE_PRODUCT_ORDER = "product_order_exchange";
    public static final String ROUTING_KEY_PRODUCT_ORDER = "product.order";

    @Bean
    public Queue productOrderQueue() {
        return new Queue(QUEUE_PRODUCT_ORDER, true);
    }

    @Bean
    public DirectExchange productOrderExchange() {
        return new DirectExchange(EXCHANGE_PRODUCT_ORDER, true, false);
    }

    @Bean
    public Binding bindingProductOrder() {
        return BindingBuilder
                .bind(productOrderQueue())
                .to(productOrderExchange())
                .with(ROUTING_KEY_PRODUCT_ORDER);
    }
}